//
//  XLScheduleStatusItemView.m
//  industry
//
//  Created by xl on 2020/12/21.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLScheduleStatusItemView.h"

@interface XLScheduleStatusItemView ()

@property (nonatomic, strong) XLLabel *titleLB;
@property (nonatomic, strong) XLLabel *tagLB;

@end
@implementation XLScheduleStatusItemView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 8.0;
        self.layer.masksToBounds = YES;
        
        [self addSubview:self.titleLB];
        [self addSubview:self.tagLB];
        
        [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.centerY.equalTo(self);
        }];
        
        [_tagLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-5);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(0, 0));
        }];
    }
    return self;
}

#pragma mark - Public
- (void)loadItemDataStatus:(BOOL)status
                       title:(NSString *)title
                         num:(NSInteger)num {
    _titleLB.text = title;
    if (num > 0) {
        _tagLB.text = [NSString stringWithFormat:@"%ld", (long)num];
        [_tagLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(18, 18));
        }];
    } else {
        _tagLB.text = @"";
        [_tagLB mas_updateConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(0, 0));
        }];
    }
    [self changeViewStatus:status];
}


- (void)changeViewStatus:(BOOL)status {
    if (status) {
        _titleLB.textColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor blueBgColor];
        _tagLB.textColor = [UIColor whiteColor];
        _tagLB.backgroundColor = [UIColor colorWithHex:0xFFFFFF alpha:0.1];
    } else {
        _titleLB.textColor = [UIColor grayFiveFontColor];
        self.backgroundColor = [UIColor grayBgColor];
        _tagLB.textColor = [UIColor redFontSecondColor];
        _tagLB.backgroundColor = [UIColor colorWithHex:0xC30808 alpha:0.1];
    }
}

#pragma mark - Setter/getter
- (XLLabel *)titleLB {
    if (!_titleLB) {
        _titleLB = [XLLabel new];
        _titleLB.font = [UIFont fontOfPingFangSCRegularWithSize:13];
        _titleLB.textColor = [UIColor grayFiveFontColor];
    }
    return _titleLB;
}


- (XLLabel *)tagLB {
    if (!_tagLB) {
        _tagLB = [XLLabel new];
        _tagLB.layer.cornerRadius = 9.0;
        _tagLB.layer.masksToBounds = YES;
        _tagLB.font = [UIFont fontOfPingFangSCRegularWithSize:12];
        _tagLB.textColor = [UIColor whiteColor];
        _tagLB.adjustsFontSizeToFitWidth = YES;
        _tagLB.textAlignment = NSTextAlignmentCenter;
    }
    return _tagLB;
}

@end
